/*    */ package site;
/*    */ 
/*    */ import database.ConnectionDB;
/*    */ import database.DatabaseMysql;
/*    */ import java.io.IOException;
/*    */ import java.io.PrintWriter;
/*    */ import java.sql.Date;
/*    */ import java.sql.ResultSet;
/*    */ import java.sql.SQLException;
/*    */ import java.text.DecimalFormat;
/*    */ import java.util.logging.Level;
/*    */ import java.util.logging.Logger;
/*    */ import javax.servlet.ServletContext;
/*    */ import javax.servlet.http.HttpServletResponse;
/*    */ 
/*    */ public class NewTopRequest extends ProcessRequest
/*    */ {
/*    */   private static final int windowSize = 20;
/*    */   private final String databaseHost;
/*    */   private final String databaseName;
/*    */   private final String databasePassword;
/*    */   private final String databaseUser;
/*    */ 
/*    */   public NewTopRequest(ServletContext context)
/*    */   {
/* 28 */     this.databaseHost = context.getInitParameter("DatabaseHost");
/* 29 */     this.databaseName = context.getInitParameter("DatabaseName");
/* 30 */     this.databasePassword = context.getInitParameter("DatabasePassword");
/* 31 */     this.databaseUser = context.getInitParameter("DatabaseUser");
/*    */   }
/*    */ 
/*    */   protected void process(HttpServletResponse response, String[] arguments)
/*    */   {
/* 38 */     response.setContentType("text/html; charset=\"UTF-8\"");
/*    */ 
/* 40 */     PrintWriter out = null;
/* 41 */     ConnectionDB connectionDB = null;
/* 42 */     DecimalFormat decimalFormat = new DecimalFormat("#.#");
/*    */     try
/*    */     {
/* 46 */       out = response.getWriter();
/*    */ 
/* 48 */       connectionDB = new DatabaseMysql(this.databaseHost, this.databaseUser, this.databasePassword, this.databaseName).getConnection();
/*    */ 
/* 50 */       String language = arguments[0];
/*    */ 
/* 52 */       out.println("<HTML><HEAD>");
/* 53 */       out.println("<a href=\"http://www.arquivo.pt\"><img src=\"http://arquivo-web.fccn.pt/logo.jpg\" alt=\"Logotipo  AWP\" border=\"0\"></a>");
/* 54 */       out.println("<META http-equiv=\"content-language\" content=\"" + language + "\">");
/*    */ 
/* 56 */       if (language.equals("en")) {
/* 57 */         out.println("<META name=\"description\" content=\"List of the rARC top contributors.\">");
/* 58 */         out.println("<META name=\"keywords\" content=\"rARC, top, contributors\">");
/* 59 */         out.println("<TITLE>The rARC contributors</TITLE>");
/*    */       }
/*    */       else {
/* 62 */         out.println("<META name=\"description\" content=\"Lista dos contribuidores mais generosos do rARC.\">");
/* 63 */         out.println("<META name=\"keywords\" content=\"rARC, tabela, contribuidores\">");
/* 64 */         out.println("<TITLE>Os contribuidores do rARC</TITLE>");
/*    */       }
/*    */ 
/* 67 */       out.println("</HEAD><BODY>");
/*    */ 
/* 73 */       if (language.equals("en")) {
/* 74 */         out.println("<CENTER><H2>Statistics about rARC</H2></CENTER>");
/* 75 */         out.println("This table shows a few statistics about <a href=http://arquivo.pt/about-the-archive/how-does-it-work/rarc/rarc-arc-replicator>rARC</a>.<p>");
/*    */       }
/*    */       else {
/* 78 */         out.println("<CENTER><H2>Estatísticas do rARC</H2></CENTER>");
/* 79 */         out.println("A seguinte tabela apresenta algumas estatísticas sobre o <a href=http://arquivo.pt/sobre-o-arquivo/funcionamento/rarc/rarc-replicador-de-arcs>rARC</a>.<p>");
/*    */       }
/*    */ 
/* 82 */       out.println("<TABLE BORDER=1 >");
/*    */ 
/* 84 */       if (language.equals("en"))
/* 85 */         out.println("<tr><th>Total contributors</th><th>Total offered space</th></tr>");
/*    */       else {
/* 87 */         out.println("<tr><th>Total contribuidores</th><th>Total espaço oferecido</th></tr>");
/*    */       }
/* 89 */       String query = "SELECT Count(User.name), Sum(Identifier.offeredSpace) FROM User, Identifier  WHERE User.email = Identifier.email AND Identifier.offeredSpace > 0 AND Identifier.lastUpdate > (SELECT DATE_SUB(curdate(), INTERVAL 1 MONTH))";
/*    */ 
/* 91 */       ResultSet resultSet = connectionDB.executeSelect(query);
/*    */ 
/* 93 */       resultSet.next();
/*    */ 
/* 95 */       out.println("<tr>");
/* 96 */       out.println("<td align=center>" + resultSet.getInt(1) + "</td>");
/* 97 */       out.println("<td align=center>" + decimalFormat.format(resultSet.getDouble(2) / 1073741824.0D) + " GB</td>");
/* 98 */       out.println("</tr>");
/*    */ 
/* 100 */       connectionDB.closeStatement();
/*    */ 
/* 102 */       out.println("</TABLE>");
/* 103 */       out.println("<P>");
/*    */ 
/* 107 */       if (language.equals("en")) {
/* 108 */         out.println("<CENTER><H2>Top 20 rARC contributors</H2></CENTER>");
/* 109 */         out.println("This table shows the 20 contributors that have offered more disk space.<p>");
/*    */       }
/*    */       else {
/* 112 */         out.println("<CENTER><H2>Os 20 maiores contribuidores do rARC</H2></CENTER>");
/* 113 */         out.println("A seguinte tabela apresenta os 20 contribuidores que disponibilizam mais espaço.<p>");
/*    */       }
/*    */ 
/* 116 */       if (language.equals("en"))
/* 117 */         out.println("<a href=\"http://arquivo-web.fccn.pt/rarc/show/list/?l=" + language + "&o=0\">Complete list</a> ");
/*    */       else {
/* 119 */         out.println("<a href=\"http://arquivo-web.fccn.pt/rarc/show/list/?l=" + language + "&o=0\">Lista completa</a> ");
/*    */       }
/* 121 */       out.println("<HR SIZE=1>");
/* 122 */       out.println("<TABLE BORDER=1 WIDTH =\"100%\">");
/*    */ 
/* 124 */       if (language.equals("en"))
/* 125 */         out.println("<tr><th>Rank</th><th>Name</th><th>Contributor since</th><th>Offered space</th></tr>");
/*    */       else {
/* 127 */         out.println("<tr><th>Posição</th><th>Nome</th><th>Contribuidor desde</th><th>Espaço oferecido</th></tr>");
/*    */       }
/* 129 */       int total = 1;
/*    */ 
/* 131 */       query = "SELECT User.name, User.initDate, Identifier.offeredSpace FROM User, Identifier WHERE User.email = Identifier.email AND Identifier.offeredSpace > 0 AND  Identifier.lastUpdate > (SELECT DATE_SUB(curdate(), INTERVAL 1 MONTH)) AND Identifier.numberCapsules > 2 ORDER BY Identifier.offeredSpace DESC limit 20";
/*    */ 
/* 136 */       resultSet = connectionDB.executeSelect(query);
/*    */ 
/* 138 */       while (resultSet.next())
/*    */       {
/* 140 */         out.println("<tr>");
/* 141 */         out.println("<td align=center>" + total + "</td>");
/* 142 */         out.println("<td align=center>" + resultSet.getString(1) + "</td>");
/* 143 */         out.println("<td align=center>" + resultSet.getDate(2).toString() + "</td>");
/* 144 */         out.println("<td align=center>" + decimalFormat.format(resultSet.getDouble(3) / 1073741824.0D) + " GB</td>");
/* 145 */         out.println("</tr>");
/*    */ 
/* 147 */         total++;
/*    */       }
/*    */ 
/* 150 */       out.println("</TABLE></CENTER>");
/* 151 */       out.println("<HR SIZE=1>");
/*    */ 
/* 153 */       if (language.equals("en"))
/* 154 */         out.println("<a href=\"http://arquivo-web.fccn.pt/rarc/show/list/?l=" + language + "&o=0\">Complete list</a> ");
/*    */       else {
/* 156 */         out.println("<a href=\"http://arquivo-web.fccn.pt/rarc/show/list/?l=" + language + "&o=0\">Lista completa</a> ");
/*    */       }
/* 158 */       out.println("</BODY></HTML>");
/* 159 */       out.flush();
/* 160 */       out.close();
/*    */ 
/* 162 */       connectionDB.closeStatement();
/*    */     }
/*    */     catch (SQLException ex) {
/* 165 */       Logger.getLogger(NewTopRequest.class.getName()).log(Level.SEVERE, null, ex);
/*    */     } catch (IOException ex) {
/* 167 */       Logger.getLogger(NewTopRequest.class.getName()).log(Level.WARNING, null, ex);
/*    */     } finally {
/* 169 */       if (out != null) {
/* 170 */         out.close();
/*    */       }
/* 172 */       if (connectionDB != null)
/*    */         try {
/* 174 */           connectionDB.close();
/*    */         }
/*    */         catch (SQLException ex)
/*    */         {
/*    */         }
/*    */     }
/*    */   }
/*    */ }

/* Location:           C:\Users\Nuno Cruz\Desktop\
 * Qualified Name:     site.NewTopRequest
 * JD-Core Version:    0.6.0
 */